package com.kpf.springcloud.controller;

import com.kpf.springcloud.pojo.KpfTopic;
import com.kpf.springcloud.pojo.PageResult;
import com.kpf.springcloud.common.ResultJson;
import com.kpf.springcloud.vo.KpfTopicLikeAndCollectStatusVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kpf.springcloud.service.FeignClientUserServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author shiwen
 * @date 2021/3/1
 */
@RestController
@Api(value = "帖子相关接口", description = "帖子相关接口") //swagger接口配置
public class TopicConsumerController {

    private Logger logger = LoggerFactory.getLogger(TopicConsumerController.class);

    @Autowired
    private FeignClientUserServer feignClientUserServer;

    /**
     * 获取所有帖子信息
     */
    @GetMapping("/consumer/topic/getTopicList")
    public ResultJson<PageResult> getTopicList(@ApiParam(value = "页码") @RequestParam(required = false, defaultValue = "1") int pageNum,
                                               @ApiParam(value = "每页数量") @RequestParam(required = false, defaultValue = "4") int pageSize,
                                               @ApiParam(value = "标题") @RequestParam(required = false, defaultValue = "") String title) {
        return feignClientUserServer.getTopicList(pageNum, pageSize, "%"+ title + "%");
    }

    @GetMapping("/consumer/topic/getById")
    public ResultJson<KpfTopic> getById() {
        return feignClientUserServer.getById();
    }

    @PostMapping("/consumer/topic/setTopicId")
    public ResultJson setTopicId(@RequestParam(value = "topicId") int topicId) {
        return feignClientUserServer.setTopicId(topicId);
    }

    /**
     * 发帖接口
     *
     * @param title
     * @param content
     * @param topicMsg
     * @return
     */
    @PostMapping("/consumer/topic/editTopic")
    public ResultJson editTopic(String title, String content, String topicMsg) {
        return feignClientUserServer.editTopic(title, content, topicMsg);
    }

    /**
     * 根据帖子id和账号id获取点赞和收藏的状态
     *
     * @param topicId
     * @return
     */
    @GetMapping("/consumer/topic/getAllStatusByTopicId")
    public ResultJson<KpfTopicLikeAndCollectStatusVO> getAllStatusByTopicId(int topicId) {
        return feignClientUserServer.getAllStatusByTopicId(topicId);
    }

    @GetMapping("/consumer/topic/getTopicListByUserId")
    ResultJson<List<KpfTopic>> getTopicListByUserId() {
        return feignClientUserServer.getTopicListByUserId();
    }

    @PostMapping("/consumer/topic/deleteTopicById")
    public ResultJson deleteTopicById(int topicId) {
        return feignClientUserServer.deleteTopicById(topicId);
    }

}